package queue;

/**
 * 循环队列
 */
public class MyCircularQueue {
    int[] elem;
    int useSize=0;
    public MyCircularQueue(int k) {
        this.elem=new int[k];
    }
    int front=0;
    int rear=0;
    public boolean enQueue(int value) {
        if(!isFull()){
            elem[rear]=value;
            rear++;
            if(rear>elem.length-1) rear=0;
            useSize++;
            return true;
        }else return false;
    }

    public boolean deQueue() {
        if(!isEmpty()){
            front++;
            if(front>elem.length-1) front=0;
            useSize--;
            return true;
        }else return false;
    }

    public int Front() {
        if(!isEmpty()) return elem[front];
        else return -1;
    }

    public int Rear() {
        if(!isEmpty()) return elem[rear];
        else return -1;
    }

    public boolean isEmpty() {
        return useSize==0;
    }

    public boolean isFull() {
        return useSize==elem.length;
    }
}
